<?php
/*************************************************

用户投资记录模块模型 - the
Author:  Wanghuabin  <17-6-28>

*************************************************/
namespace Home\Model;
use Think\Model\RelationModel;
class UserObjectModel extends RelationModel {

     public function get_all($map='',$field='*',$page=1,$pagenum=9999) {
        $data = $this->where($map)->limit(($page-1)*$pagenum,$pagenum)->field($field)->select();
        return $data;
    }
     public function get_all_group($map='',$group,$field='*',$page=1,$pagenum=9999,$order='id desc') {
        $data = $this->where($map)->limit(($page-1)*$pagenum,$pagenum)->field($field)->group($group)->order($order)->select();
        return $data;
    }
    //查询单
    public function get_one($map,$field="*"){
        $data = $this->where($map)->field($field)->find();
        return $data;
    }

    //添加
    public function log_add($data){
        $res = M('UserObject')->data($data)->add(); 
        return($res);
    }

    // //修改
    public function edit($map,$data){
        $data = $this->where($map)->save($data);
        return $data;

    }

    //删除
    public function del($map){
        $res = $this->where($map)->delete();
        return($res);
    }

    //修改
    public function updata($map,$data){
        $res= $this->where($map)->save($data);
        return($res);
    }
    //统计
    public function count($map){

        $count = M('UserObject')->where($map)->count();

        return($count);
    }

    //分组统计
    public function group_count($map){
        $count = M('UserObject')->where($map)->field('count(*)')->group('user_id')->select();

        return($count);
    }
    //统计投资额
    public function obj_sum($map){
        $count = M('UserObject')->where($map)->sum('invest');

        return($count);
    }

}